# thumbnailcontroller.py
from pysage import Actor, ActorManager
import wx
from messages import *
import util
import sys

omanager = ActorManager.get_singleton()

class ThumbnailController(Actor):
    '''this controller controls the thumbnail navigation functionality'''
    def __init__(self):
        Actor.__init__(self)
        self.lastx, self.lasty = 0,0
        self.moveRelative = False
    def mouse_pressed(self, x, y):
        pass
    def left_mouse_dclick(self, x, y):
        omanager.queue_message(UserClickMessage(position=util.vec2(x,y)))
        return True
    def mouse_motion(self, x, y, left_down):
        if left_down and not (self.lastx == 0 and self.lasty == 0) and (not x == self.lastx or not y == self.lasty):
                omanager.trigger(MoveThumbnailWindowMessage(displacement = ((x - self.lastx), (y - self.lasty))))
        self.lastx, self.lasty = x, y
    def right_mouse_pressed(self, x, y):
        return True
        omanager.queue_message(UserClickMessage(position=util.vec2(x,y)))
        return True
    def mouse_released(self, x, y):
        '''this is not called when mouse is released out of focus, therefore is not reliable'''
        pass
    def zoom(self, pos, rot):
        # if it's mac, bump up the rotation by a factor
        if sys.platform == 'darwin':
            rot = rot * 50.0
        omanager.trigger(ZoomViewerMessage(position=pos, rotation = rot))
    def enter_window(self):
        omanager.trigger(GrantFocusToViewerMessage())
    def leave_window(self):
        omanager.trigger(RevokeFocusFromViewerMessage())
    
    
    
    
    
    